package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
<#if swagger2>
@Api(tags = "${table.comment!}")
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>


    @Autowired
    private ${table.serviceName} ${'${table.serviceName}'?substring(1)?uncap_first};


    @PostMapping("/save")
    @ApiOperation("保存或者修改")
    public String save(@RequestBody ${entity} ${entity?uncap_first}){

        if(${entity?uncap_first}.getId()==null){
            ${'${table.serviceName}'?substring(1)?uncap_first}.insert${entity}(${entity?uncap_first});
        }else{
            ${'${table.serviceName}'?substring(1)?uncap_first}.update${entity}(${entity?uncap_first});
        }

        return JSON;
    }


    @GetMapping("/get")
    @ApiOperation("根据id获取")
    public String get(Long id){

        ${entity} ${entity?uncap_first}ById = ${'${table.serviceName}'?substring(1)?uncap_first}.get${entity}ById(id);

        super.setData(${entity?uncap_first}ById);

        return JSON;
    }

}
</#if>
